package com.carlosk.kandicar.view;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.carlosk.kandicar.R;
import com.carlosk.kandicar.util.ViewUtil;

/**
 * @ClassName: TitleBar
 * @Description: 所有界面的TitleBar
 * @author scofieldandroid@gmail.com
 * @date 2012-11-1 上午9:41:49
 * 
 */
public class TitleBar extends RelativeLayout {
	public Button leftBtn;// 左边的按钮
	public TextView centerTextView;// 中间的文本
	public Button rightBtn;// 右边的按钮

	public TitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public TitleBar(Context context) {
		super(context);
		init(context);
	}

	// ======================================
	private Context mContext;
	private LayoutInflater mInflater;
	@SuppressWarnings("unused")
	private Resources mRes;

	private void init(Context context) {
		this.mContext = context;
		mRes = getResources();
		mInflater = LayoutInflater.from(mContext);

		mInflater.inflate(R.layout.titlebar_two_btn_and_title, this);
		leftBtn = (Button) findViewById(R.id.btnLeft);
		leftBtn.setVisibility(View.GONE);
		rightBtn = (Button) findViewById(R.id.btnRight);
		rightBtn.setVisibility(View.GONE);
		centerTextView = (TextView) findViewById(R.id.tvTitle);

		// getViewByInflater(STYLE.TWO_BTN_AND_TITLE);//加载默认
	}

	public void initSyle(TitleSyle titleSyle, String title) {
		centerTextView.setText(title);
		ViewUtil.setViewVisible(leftBtn, View.INVISIBLE);
		ViewUtil.setViewVisible(rightBtn, View.INVISIBLE);
		switch (titleSyle) {
		case LeftBtn:
			ViewUtil.setViewVisible(leftBtn, View.VISIBLE);
			break;
		case RightBtn:
			ViewUtil.setViewVisible(rightBtn, View.VISIBLE);
			break;
		case NoBtn:

			break;
		case TwoBtn:
			ViewUtil.setViewVisible(leftBtn, View.VISIBLE);
			ViewUtil.setViewVisible(rightBtn, View.VISIBLE);
			break;

		default:
			break;
		}
	}

	public enum TitleSyle {
		LeftBtn, RightBtn, NoBtn, TwoBtn;
	}

	public void setLeftBtnOnclick(View.OnClickListener onClickListener) {
		leftBtn.setOnClickListener(onClickListener);
	}

	public void setRightBtnOnclick(View.OnClickListener onClickListener) {
		rightBtn.setOnClickListener(onClickListener);
	}
}
